declare
class Buffer
   attr
      buf first last n i

   meth init(N)
      buf:={NewArray 0 N-1 null}
      first:=0 last:=0 n:=N i:=0
   end

   meth put(X)
      ... % wait until i<n
      % now add an element:
      @buf.@last:=X
      last:=(@last+1) mod @n
      i:=@i+1
   end

   meth get(X)
      ... % wait until i>0
      % now remove an element:
      X=@buf.@first
      first:=(@first+1) mod @n
      i:=@i-1
   end
end
